package com.apestech.framework.xml.modul;

import com.apestech.framework.util.StringUtil;
import org.dom4j.Element;

/**
 * @author hup
 * @create 2019-10-11-17:41
 */
public class XmlFile extends StringUtil {
    private String allid;     //example.htw.query
    private String file;      //D:\mywork\yyesb\server\config\query\sql\example\hTw.xml
    private String lfile;
    private String id;        //query
    private String prefix;    //example.htw
    private String lprefix;
    private String nodename="select";
    private Element root;
    private Element node;
    private String xml;

    public XmlFile(){

    }

    public XmlFile(XmlFile xml){
        setXmlFile(xml);
    }

    public XmlFile(String id, Xml_File xmlfile){
        setXml_File(xmlfile);
        this.id=id;
        this.allid=this.prefix+"."+id;
    }

    public XmlFile(Xml_Id xmlid){
        setXml_Id(xmlid);
    }

    public void setXmlFile(String id, String file, String prefix){
        this.id = id;
        this.file = file;
        this.lfile = file.toLowerCase();
        this.prefix=prefix;
        this.lprefix=this.prefix.toLowerCase();
    }

    public void setXml_File(Xml_File xmlfile){
        this.root=xmlfile.getRoot();
        this.file=xmlfile.getFile();
        this.lfile=this.file.toLowerCase();
        this.prefix=xmlfile.getPrefix();
        this.lprefix=this.prefix.toLowerCase();
    }

    public void setXmlFile(XmlFile xml){
        this.root=xml.getRoot();
        this.file=xml.getFile();
        this.lfile=this.file.toLowerCase();
        this.prefix=xml.getPrefix();
        this.xml=xml.getXml();
        this.lprefix=this.prefix.toLowerCase();
    }

    public void setXml_Id(Xml_Id xmlid){
        this.allid=xmlid.getAllid();
        this.file=xmlid.getFile();
        this.lfile=this.file.toLowerCase();
        this.id=xmlid.getId();
        this.prefix=xmlid.getPrefix();
        this.nodename=xmlid.getNodeName();
        this.node=xmlid.getNode();
        this.lprefix=this.prefix.toLowerCase();
    }

    public String getId() {
        return id;
    }

    public String getFile() {
        return file;
    }

    public String getLfile() {
        return lfile;
    }

    public Element getRoot() {
        return root;
    }

    public void setRoot(Element root) {
        this.root = root;
    }

    public Element getNode() {
        return node;
    }

    public void setNode(Element node) {
        this.node = node;
    }

    public String getNodename() {
        return nodename;
    }

    public void setNodename(String nodename) {
        this.nodename = nodename;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getLprefix() {
        return lprefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
        this.lprefix=this.prefix.toLowerCase();
    }

    public String getAllid() {
        return allid;
    }

    public void setAllid(String allid) throws Exception {
        if(allid!=null){
            this.allid = allid;
            try {
                setPrefix(leftStr(this.allid, this.allid.lastIndexOf(".")));
            } catch (Exception e){
                throw new Exception("当前传的模型ID为非法数据，请重新选择操作！");
            }
        }
    }

    public void setFile(String file) {
        this.file = file;
        this.lfile=this.file.toLowerCase();
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getXml() {
        return xml;
    }

    public void setXml(String xml) {
        this.xml = xml;
    }
}
